package com.tianyi.wz.walkinggame.common;

import android.app.Activity;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class ActivityManager {

    private Set<Activity> set = new HashSet<>();

    private static ActivityManager application;

    public synchronized static ActivityManager getInstance() {
        if (null == application) {
            application = new ActivityManager();
        }
        return application;
    }

    public void addActivity(Activity activity){
        if(activity==null){
            return;
        }
        set.add(activity);
    }

    public boolean removeActivity(Activity activity){
        if(activity==null){
            return false;
        }
        return set.remove(activity);
    }

    public void exitApp(){
        Activity _activity = null;
        for(Iterator<Activity> _i = set.iterator(); _i.hasNext();){
            _activity = _i.next();
            if(_activity==null){
                continue;
            }
            _activity.finish();
        }
    }

}